<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>阶段强势股</title>
		<link href="css/text.css" rel="stylesheet" type="text/css" />
		<style type="text/css">						
			.fixedBox{
				border: 1px solid #555555;				
				white-space: nowrap;	
			}
			.fixedBox::-webkit-scrollbar {
				width: 10px;     
				height: 10px;				
			}			
		</style>		
		<script type="text/javascript" src="js/json2html.js"></script>
		<script type="text/javascript" src="js/jquery.min.js"></script>
		<script>
		
			var day = new Date();
			var gt = "";
			var tt = "";			
			window.onload = function() {								
			getSource();
			changeStyle();					
			}
						
			function time_range(beginTime, endTime) {
				var strb = beginTime.split(":");
				if (strb.length != 2) {
					return false;
				}

				var stre = endTime.split(":");
				if (stre.length != 2) {
					return false;
				}

				var b = new Date();
				var e = new Date();
				var n = new Date();

				b.setHours(strb[0]);
				b.setMinutes(strb[1]);
				e.setHours(stre[0]);
				e.setMinutes(stre[1]);

				if (n.getTime() - b.getTime() > 0 && n.getTime() - e.getTime() < 0) {
					getSource();					
					console.log(true)　　　　　　
					return true;				
				} else {
					console.log(false)
				    return false;     
				}
			}　　　
   　　　
			$(function() {
				setInterval(function() {					
				time_range("9:00","15:15")																
				},
				60000);
			})
			
			function changeStyle() {
				var obj1 = document.getElementById("towrite");				
				obj1.style.left= "0px"; 				
				obj1.style.width= "480px";	
				obj1.style.height= "620px";		
				obj1.style.fontSize="12px";							
			}					
			
			function changeCss(obj,id){				
				var alist = document.getElementById(id).getElementsByTagName("a");					
				for(var i = 0; i < alist.length; i++){				
					if(alist[i] == undefined){
						break;
					}
					alist[i].style.color = "#d2d2d3"; //给所有a标签赋原色
				}
				obj.style.color = "#00FFFF"; //令当前标签高亮				
			}			
			
			
			
			function createXmlHttp() {
				if (window.XMLHttpRequest) {
					xmlHttp1 = new XMLHttpRequest();						
				} else {
					xmlHttp1 = new ActiveXObject("Microsoft.XMLHTTP");								
				}
			}
			
			Date.prototype.Format = function (fmt) {
				var o = {
				"M+": this.getMonth() + 1, //月份
				"d+": this.getDate(), //日
				"h+": this.getHours(), //小时
				"m+": this.getMinutes(), //分
				"s+": this.getSeconds(), //秒
				"q+": Math.floor((this.getMonth() + 3) / 3), //季度
				"S": this.getMilliseconds() //毫秒
				};
				if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
				for (var k in o)
				if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
				return fmt;
			};
			
			function getLocalTime(nS) {			          
			return new Date(parseInt(nS) * 1000).Format("hh:mm:ss")}
			
			function keepTwoDecimal(num) {  
               var result = parseFloat(num);  
               if (isNaN(result)) {  
                   //alert('传递参数错误，请检查！');  
                   return false;  
               }  
               result = Math.round(num * 100) / 100;  
               return result;  
			};
			
			function UnUnicode(str) {
				return unescape(str.replace(/\\/g, "%"));
			}
			
			function getSource() {				
				if(k == 0){
					div = document.getElementById('towrite');
					div.innerHTML = '<font size="3">阶段强势股（' + n + '日）';					
					div.innerHTML = div.innerHTML + "<p>请稍等……</p>";		
				}				
				var url = "https://apphq.longhuvip.com/w1/api/index.php?Order=1&a=RealRankingInfo&st=30&apiv=w21&Type=1&c=ZhiShuRanking&PhoneOSNew=1&ZSType=7&"; 				
				createXmlHttp();				
				xmlHttp1.onreadystatechange = writeSource1;
				xmlHttp1.open("GET", url, true);
				xmlHttp1.send(null);				
			}
			
			var url11 = "https://apphq.longhuvip.com/w1/api/index.php?Order=1&a=DailyLimitPerformance&st=1000&apiv=w21&Type=4&c=HomeDingPan&PhoneOSNew=1&PidType=5&"; 				
			var url21 = "https://apphq.longhuvip.com/w1/api/index.php?Order=1&a=DailyLimitPerformance&st=1000&apiv=w21&Type=4&c=HomeDingPan&PhoneOSNew=1&PidType=4&"; 				
			var url31 = "https://apphq.longhuvip.com/w1/api/index.php?Order=1&a=DailyLimitPerformance&st=1000&apiv=w21&Type=4&c=HomeDingPan&PhoneOSNew=1&PidType=3&"; 				
			var url41 = "https://apphq.longhuvip.com/w1/api/index.php?Order=1&a=DailyLimitPerformance&st=1000&apiv=w21&Type=4&c=HomeDingPan&PhoneOSNew=1&PidType=2&"; 				
			var url51 = "https://apphq.longhuvip.com/w1/api/index.php?Order=1&a=DailyLimitPerformance&st=1000&apiv=w21&Type=4&c=HomeDingPan&PhoneOSNew=1&PidType=1&";
			
			var url12 = "https://apphis.longhuvip.com/w1/api/index.php?Order=1&a=DailyLimitPerformance&st=1000&apiv=w26&Type=4&c=HisHomeDingPan&Index=0&PidType=5&Day=";
			var url22 = "https://apphis.longhuvip.com/w1/api/index.php?Order=1&a=DailyLimitPerformance&st=1000&apiv=w26&Type=4&c=HisHomeDingPan&Index=0&PidType=4&Day=";
			var url32 = "https://apphis.longhuvip.com/w1/api/index.php?Order=1&a=DailyLimitPerformance&st=1000&apiv=w26&Type=4&c=HisHomeDingPan&Index=0&PidType=3&Day="; 				
			var url42 = "https://apphis.longhuvip.com/w1/api/index.php?Order=1&a=DailyLimitPerformance&st=1000&apiv=w26&Type=4&c=HisHomeDingPan&Index=0&PidType=2&Day=";
			var url52 = "https://apphis.longhuvip.com/w1/api/index.php?Order=1&a=DailyLimitPerformance&st=1000&apiv=w26&Type=4&c=HisHomeDingPan&Index=0&PidType=1&Day=";
			
			var datas = "";
			var datas2 = "";
			var k = 0;
			var zxs = "";	
			function writeSource1() { 
				if (xmlHttp1.readyState == 4) { 																
					var data = xmlHttp1.responseText
					//document.write(data);
					
					//tt = data.match(/\"Day\":\[\"(\S*)\"\],/)[1];	//最后交易日										
					tt = data.match(/"Day":\["(\S*)/)[1].split('"]')[0];
					var url1 = url11;
					var url2 = url21;
					var url3 = url31;
					var url4 = url41;
					var url5 = url51;					
					var day1 = new Date();
					var ts = day1.Format("yyyy-MM-dd");
					//alert(ts);
					if(tt != ts){
						url1 = url12 + tt;
						url2 = url22 + tt;
						url3 = url32 + tt;
						url4 = url42 + tt;
						url5 = url52 + tt;
					}
					var url = "";
					var p = 0;
					for (i = 1; i < 6 ; i++)
					{	
						if(i == 1){
							url = url1;
							p = 5;
						}
						if(i == 2){
							url = url2;
							p = 4;
						}
						if(i == 3){
							url = url3;
							p = 3;
						}
						if(i == 4){
							url = url4;
							p = 2;
						}
						if(i == 5){
							url = url5;
							p = 1;
						}						
						getSourcehq(url , p);						
					}
					var datas1 = datas; //最后交易日数据
					
					if(k == 0){  //刷新时才调用
						k = 1;
						datas = "";					
						day = new Date(tt);
						gethis(); //交易日向前推算
						datas2 = datas;  //历史交易日数据
					}
					datas = datas1 + datas2;
					//document.write(datas);
					writeSource2();	
				}				
			}
											
			var n = 30; //统计区间，交易日天数
			function gethis() {						
				for (j = 1; j < n; j++){											
					gethisdate();					
				}				
			}
								
			function gethisdate() {		//历史交易日推算									
				day.setTime(day.getTime());				
				for (i = 1; i < 100; i++){	//节假日																										
					day.setTime(day.getTime() - i*24*60*60*1000);
					tt = day.Format("yyyy-MM-dd");
					//alert(tt)
					var url = "https://apphis.longhuvip.com/w1/api/index.php?Order=1&a=RealRankingInfo&st=30&apiv=w26&Type=1&c=ZhiShuRanking&ZSType=7&Date=" + tt + "&"; 							
					var xhr = new XMLHttpRequest();	
					xhr.open("GET", url, false);//同步 
					xhr.send(null)																										
					var data = xhr.responseText;					
					if(data.indexOf("MYSQL数据库链接出错!") == -1){
					
						var url = "";
						url1 = url12 + tt;
						url2 = url22 + tt;
						url3 = url32 + tt;
						url4 = url42 + tt;
						url5 = url52 + tt;
						for (i = 1; i < 6 ; i++){	
							if(i == 1){
								url = url1;
							}
							if(i == 2){
								url = url2;
							}
							if(i == 3){
								url = url3;
							}
							if(i == 4){
								url = url4;
							}
							if(i == 5){
								url = url5;
							}							
							getSourcehq(url , 0);							
						}										
						break;						
					}
				}				
			}
						
			function getSourcehq(url , p){	//获取数据
				if (window.XMLHttpRequest) {
					xmlHttp = new XMLHttpRequest();								
				} else {
					xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");							
				}
				xmlHttp.open("GET", url, false);  //同步方式
				xmlHttp.send(null);				
				
				var data = xmlHttp.responseText					
				data = data.replace("\[\[\]","\[\]");
				//document.write(data);
				if (data.indexOf('\"' + 'info' + '\"' + ':\[\]') == -1 ) { 					
					//data = data.replace(/ /g,"").match(/(\S*)\]\],\"/)[1] + ']]';
					data = data.replace(/ /g,"").match(/\{\"info\":\[\[(\S*)\]\],\"/)[1] + '],';
					data = data.replace(/(\[\").*?(?=\])/g,function(word){ str = word.match(/\[(\S*)/)[1]; return '{"code":' + str.split(',')[0] + ',"name":' + str.split(',')[1] + ',"ztyy":' + str.split(',')[5] + ',"lb":"' + p + '"';});										
					//document.write(data);
					datas += data;
				}																
			}	
			
			var dms = "";
			var bb = "";
			var datasp = "";
			function writeSource2() {	
				var ss = datas.split("],{");
				for (i = 0; i < ss.length ; i++){
					var dm = ss[i].match(/\"code\":\"(\S*)\",\"name/)[1];
					var cs = 0; 					
					if(dms.indexOf(dm) == -1){						
						dms += dm + ";";
						var cc = datas.split(dm);
						cs = cc.length - 1;
						if(cs > 1){
							bb += ss[i] + ',"cs":' + cs + '},{';
						}						
					}
				}				
				datasp = bb + '}';
				datasp = "[" + datasp.replace("},{}","}") + "]";
				getdata("1");
			}
			
			var gl = "";  //高亮
			var fx = "0";
			var px = 0;			
			function getdata(p) {
				//alert(p);
				div = document.getElementById('towrite');
				var p1 = "<a href='javascript:void(0)' id='px1' onclick='getdata(" + "\"1\"" + ")'>" + "按连板数量排序" + "</a>";
				var p2 = "<a href='javascript:void(0)' id='px2' onclick='getdata(" + "\"2\"" + ")'>" + "按涨停次数排序" + "</a>";
				var p3 = "<a href='javascript:void(0)' id='px3' onclick='getdata(" + "\"3\"" + ")'>" + "按涨停原因排序" + "</a>";
				div.innerHTML = '<font size="3">阶段强势股（' + n + '日）';						
				div.innerHTML += "<p>" + p1 + p2 + p3 + "</p>";
				
				var aObj = document.getElementById('px' + p);
				gl = aObj.innerText;
				gl = gl.replace("按","").replace("排序","");
								
				if(p != px){  //切换类别 清零				
					fx = 1;
				}						
				px = p;	
				if(fx == "0"){
					aObj.innerText += "↑";	
					fx = "1";		
				}else{
					aObj.innerText += "↓";
					fx = "0";
				}			
				aObj.style.color = "#FFA07A"; 
				
				var result = JSON.parse(datasp); //JSON字符串转换为对象				
				function up(a,b){
					if(p == "1"){
						if(fx == "0"){				
							return b.lb-a.lb
						}else{
							return a.lb-b.lb
						}
					}
					else if(p == "2"){						
						if(fx == "0"){				
							return b.cs-a.cs
						}else{
							return a.cs-b.cs
						}
					}else{
						if(fx == "0"){				
							return b.ztyy.localeCompare(a.ztyy) //字符串排序
						}else{
							return a.ztyy.localeCompare(b.ztyy) 
						}						
					}					
				}
				
				result.sort(up);
				result = JSON.stringify( result );
				//document.write(result);				
				var data = '{"List":' + result + '}';	
				data = data.replace(/\"lb\":\"5\"/g,'"lb":"4板以上"');
				//document.write(data);
							
				var transform_aa = [   									
				{"tag":"p", children:function(){return(json2html.transform(this.List, transform_bb));}}				
				];
				
				var transform_bb= 
				{"tag":"p", children:[
				{"tag":"p", children:[                            						
				{"tag": "li", "html":"<a href='http://www.treeid/code_${code}' onclick='changeCss(this,\"gg\")'>${code} ${name} &nbsp;&nbsp;涨停原因：<font color=#FFA500>${ztyy}</font>&nbsp;&nbsp;&nbsp;&nbsp;连板数量：${lb}&nbsp;&nbsp;&nbsp;&nbsp;涨停次数：${cs}/"+ n + "</a> "}, 							
				]}]};
				var html = json2html.transform(data, transform_aa);					
				div.innerHTML += "<span id='gg'>" + html;
				
				//高亮
				var content = document.getElementById("towrite").innerHTML;
				var reg = new RegExp("(&nbsp;"  + gl + ")", "g");  
				var str = content;  
				var newstr = str.replace(reg, "<font color=#FF6633>$1</font>");
				document.getElementById("towrite").innerHTML = newstr;		
			}			
		</script>
	</head>
	<body>		
		<div id="towrite" class="fixedBox"></div>
	</body>
</html>